<?php

class SnsController  extends AppController{

    public $faces = array(
	'1'=>'微笑','2'=>'呲牙笑','3'=>'偷笑','4'=>'吐舌','5'=>'色迷迷','6'=>'害羞','7'=>'耍酷','8'=>'晕','9'=>'疑惑','10'=>'流汗',
	'11'=>'难过','12'=>'不满','13'=>'吃惊','14'=>'不明白','15'=>'生气','16'=>'暴怒','17'=>'睡觉','18'=>'闭嘴','19'=>'衰','20'=>'猪头'	,
	'21'=>'红心','22'=>'心碎','23'=>'鲜花','24'=>'凋谢','25'=>'晚安','26'=>'拍砖','27'=>'金钱','28'=>'便便','29'=>'呕吐','30'=>'扁你',
	'31'=>'好','32'=>'鼓掌','33'=>'支持你','34'=>'鄙视你','35'=>'投降','36'=>'胜利','37'=>'OK','38'=>'握手','39'=>'抱抱','40'=>'抽你',
	'41'=>'亲一个','42'=>'委屈','43'=>'痛哭','44'=>'惊叫','45'=>'抓狂','46'=>'烧香','47'=>'期望','48'=>'喊话','49'=>'爽歪歪');

	public function beforeFilter() {
	    parent::beforeFilter(); 
		$this->C_auth->autoRedirect = false; 
	    $this->C_auth->allowedActions = array('index','addmsg','addhui','listmsg','listcomment','deluseraddhui');

	}


	public function index() {
	
	}
	
	public function addmsg() {
	    $content = Request::get_args('content');
        header('Content-Type: text/html; charset='.Param::read('App.encoding'));		
		if(empty($content))exit('-1');
		$time = date("Y-m-d H:i:s");
		$safedata = array();		
		$safedata['snsmood']['user_id'] = $this->my->id;
		$safedata['snsmood']['user_name'] = $this->my->username;
		$safedata['snsmood']['user_ico'] = $this->my->user_ico;		
		$safedata['snsmood']['mood'] = $content;		
		$safedata['snsmood']['comments'] = 0;
		$safedata['snsmood']['add_time'] = $time;	
		$inid =POP::exe('[@@:UM snsmood][@@:QU save]',$safedata);	
		if($inid){
			$title = $this->clear_format_message($content);
			$contentstr = $this->mood_format_message($content,$inid);
			$fabuma = "发布了";
			if(!empty($this->format_img) || !empty($this->format_video))$fabuma = "上传了";				
		    $str ='
        <div  class="stream" id="psp_stream_moods_'.$inid.'">
	
			<div class="avatar">
				  <a target="_blank" href=""  class="YK_id" _hz="tl_avatar">
					   <img title="贾宗超" src="http://g1.ykimg.com/0130391F4551528AE486A2036445483378CF62-8588-7A10-6F67-337CF5A1E04C">
				  </a>
			</div>
			<!--avatar end-->
			<div class="feed">
				<div class="username">
					<span>
						<a target="_blank" href=""  class="YK_id" _hz="tl_name">'.$safedata['snsmood']['user_name'].'</a> 
						<span _hz="tl_icon"> 
							 <span class="YK_cert">
								<a target="_blank" title="认证用户" href="http://www.youku.com/help/view/fid/17#q7"><span class="ico_cert_s"></span></a>
							 </span>
						</span>
					</span>
					<span class="act">'.$fabuma.'</span>	
					<a title="" target="video" href="" _hz="tl_vtitle">'.$title.'</a>
				</div>
			    <!--username end-->			

				
				'.$contentstr.'
				<!--text end-->
			
			    <!--源动态-->
			
				<div class="clear"></div>
				<div class="panel">
					<span class="actions">				
						<span class="feed_trans">					
							<a _hz="tl_st_trans" href="javascript:;" >转发</a>					
						</span>
						<span class="splite">|</span>					
						<span  class="feed_comment" >
							<a  href="javascript:;" onclick="pinglun(\''.$inid.'\')" >评论(0)</a>
						</span>
					</span>
					<span class="timestamp"><a title="'.$time.'"  href="#" >'.substr(substr($time,0,-3),-11).'</a></span>
					<span class="via">来自 <a target="_blank" href="http://www.youku.com/" _hz="tl_st_source">优酷</a></span>
				</div>
				<div class="YK_comments" style="display: none;" id="pspcomments_'.$inid.'">	
					<div class="editor_wrap" id="">
						<div class="YK_toolbar">
							<div class="tool">
								<div class="insert_emoticon">
									<div class="dropmenu" id="">
										<div class="handle" style=" width:35px;">
											<a href="javascript:;" onclick="psp_$(\'pspfaceshow_'.$inid.'\').style.display = (psp_$(\'pspfaceshow_'.$inid.'\').style.display ==\'none\')?\'block\':\'none\';smileControl(\''.$inid.'\');" title="添加表情"><span class="icon"><em>表情</em></span></a>
										</div><!-- .dropmenu -->
										<div class="panel" loading="false" style="display: none;" id="pspfaceshow_'.$inid.'" >
											 <div class="faces">
													<div  class="ico__faces_act" id="face_list_menuimWin_'.$inid.'">							
														<div lang="1" title="微笑" class="emItem" ></div>
														<div lang="2" title="呲牙笑" class="emItem" ></div>
														<div lang="3" title="偷笑" class="emItem" ></div>
														<div lang="4" title="吐舌" class="emItem" ></div>
														<div lang="5" title="色迷迷" class="emItem" ></div>
														<div lang="6" title="害羞" class="emItem " ></div>
														<div lang="7" title="耍酷" class="emItem" ></div>
														<div lang="8" title="晕" class="emItem" ></div>
														<div lang="9" title="疑惑" class="emItem" ></div>
														<div lang="10" title="流汗" class="emItem" ></div>
														<div lang="11" title="难过" class="emItem" ></div>
														<div lang="12" title="不满" class="emItem" ></div>
														<div lang="13" title="吃惊" class="emItem" > </div>
														<div lang="14" title="不明白" class="emItem" ></div>
														<div lang="15" title="生气" class="emItem" ></div>
														<div lang="16" title="暴怒" class="emItem" ></div>
														<div lang="17" title="睡觉" class="emItem" ></div>
														<div lang="18" title="闭嘴" class="emItem" ></div>
														<div lang="19" title="衰" class="emItem" ></div>
														<div lang="20" title="猪头" class="emItem" ></div>
														<div lang="21" title="红心" class="emItem" ></div>
														<div lang="22" title="心碎" class="emItem" ></div>
														<div lang="23" title="鲜花" class="emItem" ></div>
														<div lang="24" title="凋谢" class="emItem" ></div>
														<div lang="25" title="晚安" class="emItem" ></div>
														<div lang="26" title="拍砖" class="emItem" ></div>
														<div lang="27" title="金钱" class="emItem" ></div>
														<div lang="28" title="便便" class="emItem" ></div>
														<div lang="29" title="呕吐" class="emItem" ></div>
														<div lang="30" title="扁你" class="emItem" ></div>
														<div lang="31" title="好" class="emItem" ></div>
														<div lang="32" title="鼓掌" class="emItem" ></div>
														<div lang="33" title="支持你" class="emItem" ></div>
														<div lang="34" title="鄙视你" class="emItem" ></div>
														<div lang="35" title="投降" class="emItem" ></div>
														<div lang="36" title="胜利" class="emItem" ></div>
														<div lang="37" title="OK" class="emItem" ></div>
														<div lang="38" title="握手" class="emItem" ></div>
														<div lang="39" title="抱抱" class="emItem" ></div>
														<div lang="40" title="抽你" class="emItem" ></div>
														<div lang="41" title="亲一个" class="emItem" ></div>
														<div lang="42" title="委屈" class="emItem" ></div>
														<div lang="43" title="痛哭" class="emItem" ></div>
														<div lang="44" title="惊叫" class="emItem" ></div>
														<div lang="45" title="抓狂" class="emItem" ></div>
														<div lang="46" title="烧香" class="emItem" ></div>
														<div lang="47" title="期望" class="emItem" ></div>
														<div lang="48" title="喊话" class="emItem" ></div>
														<div lang="49" title="爽歪歪" class="emItem" ></div>
													</div>	
											 </div>
										</div>
									</div><!-- .insert_emoticon -->
								</div><!-- .insert_emoticon -->
							</div><!-- .tools -->
						</div><!-- .YK_toolbar -->
						<div class="editor">
							<textarea class="form_input" onblur="this.style.borderBottomColor=\'#A0A0A0\'"  onfocus="this.style.borderBottomColor=\'#3eabff\'" onkeyup="javascript:psp_$(\'pspmsgnum_'.$inid.'\').innerHTML=\'\'+(this.value.length)+\'/300\';return isMaxLen(this);"  maxlength="300" id="form_input_post_'.$inid.'" accesskey="1" style="resize: none; height: 30px; overflow: hidden;" tabindex="1"></textarea>	
							<div class="transmit">
								<p><input type="checkbox" class="sharechk" id="transchk_'.$inid.'"><label for="transchk123157817">同时转发</label></p>
							</div><!-- .transmit -->
							<div class="action">
								<div  class="form_btn form_btn_s form_btnmaj_s"><span class="form_btn_text" _hz="tl_comment_pub"  onclick="huipinglun(\''.$inid.'\')">评论</span></div>
							</div><!-- .action -->
							<span class="counter" id="pspmsgnum_'.$inid.'">0/300</span>
							<div class="clear"></div>
							<div style="font-size: 14px; line-height: 30px; padding: 0px 5px; border-width: 1px; border-style: solid; overflow: hidden; position: absolute; visibility: hidden; z-index: -1;">
							</div>
						</div><!-- .editor -->
						<div class="clear"></div>
					</div><!-- .editor_wrap -->
					<div class="streams" id="pspstreams_'.$inid.'">
					
				    </div>
				</div>
		    </div><!--feed end-->			
		    <div class="clear"></div>
	
        </div><!-- .stream -->
        <div class="spacer" ></div>				
			';			
			echo $str;
			exit;
        }else {
            exit('-1');
        }		
	}
	
	public $setaddhui = array();
	
	public function _setaddhui($str) {
	     $temp = explode(":",$str);
		 if(isset($temp[0]) && !empty($temp[0])){
		      $this->setaddhui[0] = intval($temp[0]);
		 }
		 $str ='';
		 foreach($temp as $k =>$v) {
		     if($k==0)continue;
			 $str .=$v;
		 }
		 if($str)$this->setaddhui[1] = $str;
		 return '';
	}
	
	public function deluseraddhui() {
	    $mcid = Request::get_args('mcid');
	    $mid = Request::get_args('mid');
	    $id = Request::get_args('id');		
		$query = array('conditions'=>array('snsmoodcommenthui.id' => $id,'snsmoodcommenthui.user_id' => $this->my->id));			
		if(POP::exe('[@@:UM snsmoodcommenthui][@@:QU del]',$query)) {
            exit(1);
		} else {
			exit(-1);
		}	
			
	}	
	
	public function addhui() {
	    $content = Request::get_args('content');
	    $mid = Request::get_args('mid');		
        header('Content-Type: text/html; charset='.Param::read('App.encoding'));		
		if(empty($content) || empty($mid))exit('-1');
		$content = preg_replace("/\{\@(.+?)\@\}\:/ies", "\$this->_setaddhui('\\1')", $content);	
		$query = array(
			'conditions' => array('snsmood.id' => $mid), 
			'fields' => array('snsmood.user_id'), 
		);
		$moodinfo = POP::exe('[@@:UM snsmood][@@:QU find:first]',$query);	
		if(empty($moodinfo))exit('-1');		
		if(!empty($this->setaddhui)) {
			$query = array(
				'conditions' => array('snsmoodcomment.id' => $this->setaddhui[0],'snsmoodcomment.visitor_name' => $this->setaddhui[1],'snsmoodcomment.mood_id' => $mid), 
				'fields' => array('snsmoodcomment.id'), 
			);
			$moodcommentinfo = POP::exe('[@@:UM snsmoodcomment][@@:QU find:first]',$query);	
			if(empty($moodcommentinfo))exit('-1');										
			$indata = array();
			$indata['mcid'] = $this->setaddhui[0];			
			$indata['user_id'] = $this->my->id;
			$indata['user_name'] = $this->my->username;
			$indata['user_ico'] = $this->my->user_ico;			
			$indata['add_time'] = date("Y-m-d H:i:s");		
			$indata['content'] = $content;														
			$safeData['snsmoodcommenthui'] =$indata;						
			if(POP::exe('[@@:UM snsmoodcommenthui][@@:QU save]',$safeData)) {	
				exit('1');
			}else {
				exit('-1');
			}	
		}else {		
			$safedata = array();	
			$safedata['snsmoodcomment']['mood_id'] = $mid;			
			$safedata['snsmoodcomment']['host_id'] = $moodinfo['snsmood']['user_id'];			
			$safedata['snsmoodcomment']['visitor_id'] = $this->my->id;
			$safedata['snsmoodcomment']['visitor_name'] = $this->my->username;
			$safedata['snsmoodcomment']['visitor_ico'] = $this->my->user_ico;		
			$safedata['snsmoodcomment']['content'] = $content;
			$safedata['snsmoodcomment']['add_time'] = date("Y-m-d H:i:s");
			$query  = array();		
			$query['keyid'] = $mid;				
			$query['set']['snsmood'] = array('comments +' => 1);							
			if(POP::exe('[@@:UM snsmoodcomment][@@:QU save]',$safedata) && POP::exe('[@@:UM snsmood][@@:QU save]',$query)){
				exit('1');
			}else {
				exit('-1');
			}
		}		
	}	
	
	public function listmsg() {
	    $page = Request::get_args('page');
        header('Content-Type: text/html; charset='.Param::read('App.encoding'));
        $conditions = array();	
        $url_this = 'http://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
        $tb = array('model' => 'snsmood',
				    'fields' => array('snsmood.*'),
					'conditions' => $conditions,
					'order' => ' snsmood.add_time desc ',
					'limit' => '3',
					'group' => '',
					'url' => preg_replace("/&page=([^&]+)/","",$url_this),
					'page' => $page,
					'plist' => 6				
				); 
	    $result =  $this->fpage($tb);
		$str = '';		
        foreach($result['data'] as $v) {
			$title = $this->clear_format_message($v['snsmood']['mood']);
			$contentstr = $this->mood_format_message($v['snsmood']['mood'],$v['snsmood']['id']);
			$fabuma = "发布了";
			if(!empty($this->format_img) || !empty($this->format_video))$fabuma = "上传了";			
		    $str .='
        <div  class="stream" id="psp_stream_moods_'.$v['snsmood']['id'].'">
	
			<div class="avatar">
				  <a target="_blank" href=""  class="YK_id" _hz="tl_avatar">
					   <img title="贾宗超" src="http://g1.ykimg.com/0130391F4551528AE486A2036445483378CF62-8588-7A10-6F67-337CF5A1E04C">
				  </a>
			</div>
			<!--avatar end-->
			<div class="feed">
				<div class="username">
					<span>
						<a target="_blank" href=""  class="YK_id" _hz="tl_name">'.$v['snsmood']['user_name'].'</a> 
						<span _hz="tl_icon"> 
							 <span class="YK_cert">
								<a target="_blank" title="认证用户" href="http://www.youku.com/help/view/fid/17#q7"><span class="ico_cert_s"></span></a>
							 </span>
						</span>
					</span>
					<span class="act">'.$fabuma.'</span>	
					<a title="" target="video" href="" _hz="tl_vtitle">'.$title.'</a>
				</div>
			    <!--username end-->			

				
				'.$contentstr.'
				<!--text end-->
			
			    <!--源动态-->
			
				<div class="clear"></div>
				<div class="panel">
					<span class="actions">				
						<span class="feed_trans">					
							<a _hz="tl_st_trans" href="javascript:;" >转发</a>					
						</span>
						<span class="splite">|</span>					
						<span  class="feed_comment" >
							<a  href="javascript:;" onclick="pinglun(\''.$v['snsmood']['id'].'\')" >评论('.$v['snsmood']['comments'].')</a>
						</span>
					</span>
					<span class="timestamp"><a title="'.$v['snsmood']['add_time'].'"  href="#" >'.substr(substr($v['snsmood']['add_time'],0,-3),-11).'</a></span>
					<span class="via">来自 <a target="_blank" href="http://www.youku.com/" _hz="tl_st_source">优酷</a></span>
				</div>
				<div class="YK_comments" style="display: none;" id="pspcomments_'.$v['snsmood']['id'].'">	
					<div class="editor_wrap" id="">
						<div class="YK_toolbar">
							<div class="tool">
								<div class="insert_emoticon">
									<div class="dropmenu" id="">
										<div class="handle" style=" width:35px;">
											<a href="javascript:;" onclick="psp_$(\'pspfaceshow_'.$v['snsmood']['id'].'\').style.display = (psp_$(\'pspfaceshow_'.$v['snsmood']['id'].'\').style.display ==\'none\')?\'block\':\'none\';smileControl(\''.$v['snsmood']['id'].'\');" title="添加表情"><span class="icon"><em>表情</em></span></a>
										</div><!-- .dropmenu -->
										<div class="panel" loading="false" style="display: none;" id="pspfaceshow_'.$v['snsmood']['id'].'" >
											 <div class="faces">
													<div  class="ico__faces_act" id="face_list_menuimWin_'.$v['snsmood']['id'].'">							
														<div lang="1" title="微笑" class="emItem" ></div>
														<div lang="2" title="呲牙笑" class="emItem" ></div>
														<div lang="3" title="偷笑" class="emItem" ></div>
														<div lang="4" title="吐舌" class="emItem" ></div>
														<div lang="5" title="色迷迷" class="emItem" ></div>
														<div lang="6" title="害羞" class="emItem " ></div>
														<div lang="7" title="耍酷" class="emItem" ></div>
														<div lang="8" title="晕" class="emItem" ></div>
														<div lang="9" title="疑惑" class="emItem" ></div>
														<div lang="10" title="流汗" class="emItem" ></div>
														<div lang="11" title="难过" class="emItem" ></div>
														<div lang="12" title="不满" class="emItem" ></div>
														<div lang="13" title="吃惊" class="emItem" > </div>
														<div lang="14" title="不明白" class="emItem" ></div>
														<div lang="15" title="生气" class="emItem" ></div>
														<div lang="16" title="暴怒" class="emItem" ></div>
														<div lang="17" title="睡觉" class="emItem" ></div>
														<div lang="18" title="闭嘴" class="emItem" ></div>
														<div lang="19" title="衰" class="emItem" ></div>
														<div lang="20" title="猪头" class="emItem" ></div>
														<div lang="21" title="红心" class="emItem" ></div>
														<div lang="22" title="心碎" class="emItem" ></div>
														<div lang="23" title="鲜花" class="emItem" ></div>
														<div lang="24" title="凋谢" class="emItem" ></div>
														<div lang="25" title="晚安" class="emItem" ></div>
														<div lang="26" title="拍砖" class="emItem" ></div>
														<div lang="27" title="金钱" class="emItem" ></div>
														<div lang="28" title="便便" class="emItem" ></div>
														<div lang="29" title="呕吐" class="emItem" ></div>
														<div lang="30" title="扁你" class="emItem" ></div>
														<div lang="31" title="好" class="emItem" ></div>
														<div lang="32" title="鼓掌" class="emItem" ></div>
														<div lang="33" title="支持你" class="emItem" ></div>
														<div lang="34" title="鄙视你" class="emItem" ></div>
														<div lang="35" title="投降" class="emItem" ></div>
														<div lang="36" title="胜利" class="emItem" ></div>
														<div lang="37" title="OK" class="emItem" ></div>
														<div lang="38" title="握手" class="emItem" ></div>
														<div lang="39" title="抱抱" class="emItem" ></div>
														<div lang="40" title="抽你" class="emItem" ></div>
														<div lang="41" title="亲一个" class="emItem" ></div>
														<div lang="42" title="委屈" class="emItem" ></div>
														<div lang="43" title="痛哭" class="emItem" ></div>
														<div lang="44" title="惊叫" class="emItem" ></div>
														<div lang="45" title="抓狂" class="emItem" ></div>
														<div lang="46" title="烧香" class="emItem" ></div>
														<div lang="47" title="期望" class="emItem" ></div>
														<div lang="48" title="喊话" class="emItem" ></div>
														<div lang="49" title="爽歪歪" class="emItem" ></div>
													</div>	
											 </div>
										</div>
									</div><!-- .insert_emoticon -->
								</div><!-- .insert_emoticon -->
							</div><!-- .tools -->
						</div><!-- .YK_toolbar -->
						<div class="editor">
							<textarea class="form_input"  onblur="this.style.borderBottomColor=\'#A0A0A0\'"  onfocus="this.style.borderBottomColor=\'#3eabff\'" onkeyup="javascript:psp_$(\'pspmsgnum_'.$v['snsmood']['id'].'\').innerHTML=\'\'+(this.value.length)+\'/300\';return isMaxLen(this);"  maxlength="300" id="form_input_post_'.$v['snsmood']['id'].'" accesskey="1" style="resize: none; height: 30px; overflow: hidden;" tabindex="1"></textarea>	
							<div class="transmit">
								<p><input type="checkbox" class="sharechk" id="transchk_'.$v['snsmood']['id'].'"><label for="transchk123157817">同时转发</label></p>
							</div><!-- .transmit -->
							<div class="action">
								<div  class="form_btn form_btn_s form_btnmaj_s"><span class="form_btn_text" _hz="tl_comment_pub"  onclick="huipinglun(\''.$v['snsmood']['id'].'\')">评论</span></div>
							</div><!-- .action -->
							<span class="counter" id="pspmsgnum_'.$v['snsmood']['id'].'">0/300</span>
							<div class="clear"></div>
							<div style="font-size: 14px; line-height: 30px; padding: 0px 5px; border-width: 1px; border-style: solid; overflow: hidden; position: absolute; visibility: hidden; z-index: -1;">
							</div>
						</div><!-- .editor -->
						<div class="clear"></div>
					</div><!-- .editor_wrap -->
					<div class="streams" id="pspstreams_'.$v['snsmood']['id'].'">
					
				    </div>
				</div>
		    </div><!--feed end-->			
		    <div class="clear"></div>
	
        </div><!-- .stream -->
        <div class="spacer" ></div>				
			';
		
		}
		echo $str;
		exit;
	}

	public function listcomment() {
	    $page = Request::get_args('page');
		if(empty($page))$page=1;
	    $mid = Request::get_args('mid');		
        header('Content-Type: text/html; charset='.Param::read('App.encoding'));
        $conditions = array();	
		$conditions['snsmoodcomment.mood_id'] = $mid;		
        $url_this = 'http://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
        $tb = array('model' => 'snsmoodcomment',
				    'fields' => array('snsmoodcomment.*'),
					'conditions' => $conditions,
					'order' => ' snsmoodcomment.add_time desc ',
					'limit' => '20',
					'group' => '',
					'url' => preg_replace("/&page=([^&]+)/","",$url_this),
					'page' => $page,
					'plist' => 6				
				); 
	    $result =  $this->fpage($tb);
		$str = '';
        foreach($result['data'] as $v) {
			$query = array(
				'conditions' => array('snsmoodcommenthui.mcid' => $v['snsmoodcomment']['id']), 
				'fields' => array('snsmoodcommenthui.*'),
				'order' => 'snsmoodcommenthui.id desc',				 
			);
			$huicontent = POP::exe('[@@:UM snsmoodcommenthui][@@:QU find:all]',$query);			
			$huicontentstr ='';		
		    if(!empty($huicontent)) {
			
			      foreach($huicontent as $k1 =>$v1) {
				       $v1 = $v1['snsmoodcommenthui'];
				       $deltemp = '';
				       if($v1['user_id']==$this->my->id){
					       $deltemp = '<div class="huireply"><a href="javascript:;"  onclick="delhuiuserpinglun(\''.$mid.'\',\''.$v['snsmoodcomment']['id'].'\',\''.$v1['id'].'\');">删除</a></div>';
					   }				  
				       $huicontentstr .='
							<div class="huicomment">
								<div class="huiavatar">
									 <a target="_blank" href="" class="YK_id" >
										  <img title="'.$v1['user_name'].'" src="'.$v1['user_ico'].'">
									 </a>
								</div>
								<div class="huitext">
									<span class="username"><a target="_blank" href="http://weibo.com/1932628082"  class="YK_id" _hz="tl_comment_name">'.$v1['user_name'].'</a>：</span>'.$this->face_format_message($v1['content']).'
									<span style="color:#909090" class="pubdate">('. substr(substr($v1['add_time'],0,-3),-11).')</span>
								</div>
							  '.$deltemp.'
							</div><div class="clear"></div>';			     
				  }			
			
			      $huicontentstr = '<div class="huistreams">'.$huicontentstr.'</div>';
			}
		
		
			$str .= '<div class="comment">
							<div class="avatar">
								 <a target="_blank" href=""  class="YK_id" >
									  <img title="专业定制汽车潮牌个性脚垫" src="http://tp3.sinaimg.cn/1932628082/50/5638836686/0">
								 </a>
							</div>
							<div class="text">
								<span class="username"><a target="_blank" href="http://weibo.com/1932628082" class="YK_id" >'.$v['snsmoodcomment']['visitor_name'].'</a>：</span>'.$this->face_format_message($v['snsmoodcomment']['content']).'<span style="color:#909090" class="pubdate">('. substr(substr($v['snsmoodcomment']['add_time'],0,-3),-11).')</span>
							</div>
							<div class="reply"><a href="javascript:;"  onclick="huiuserpinglun(\''.$mid.'\',\''.$v['snsmoodcomment']['id'].'\',\''.$v['snsmoodcomment']['visitor_name'].'\');" >回复</a></div>'.$huicontentstr.'</div>
			';		    
		}
		if($str && $result['page']['pageCount']>1) {		    
		    if($page+1>$result['page']['pageCount']) {
		        $str .='<div  class="psphuidownpage" id="psphuidownpage_'.$mid.'"  onclick="pinglun('.$mid.',1);"><b>没有更多的回复了，返回顶部</b></div>';					
			}else {				
		        $str .='<div  class="psphuidownpage" id="psphuidownpage_'.$mid.'" onclick="pinglun('.$mid.','.($page+1).');"><b>查看更多回复</b></div>';							
			}
		}
		echo $str;
		exit;		
	}

	function clear_format_message($content) {
		$content = preg_replace("/\[img\:(.+?)\:\]/is", "", $content);
		$content = preg_replace("/\[video\:(.+?)\:\]/is", "", $content);				
		$content = preg_replace("/\{\:(.+?)\:\}/is", "", $content);
		return $content;
	}	
	
	function mood_format_message($content,$id=0) {
		$old = $content;
		$content = preg_replace("/\[img\:(.+?)\:\]/is", "", $content);
		$content = preg_replace("/\[video\:(.+?)\:\]/is", "", $content);		
		$msgcon = '<div class="text more">'.$this->face_format_message($content).'</div>';
		$this->format_img = array();
		$this->format_video = array();	
		$this->format_count = 1;			
		$content = preg_replace("/\[img\:(.+?)\:\]/ies", "\$this->_setimg('\\1',\$id)", $old);
		$content = preg_replace("/\[video\:(.+?)\:\]/ies", "\$this->_setvideo('\\1',\$id)", $content);
		$newcontent = '';
		foreach($this->format_img as $v) {
			$newcontent .=$v;
		}
		foreach($this->format_video as $v) {
			$newcontent .=$v;
		}		
		return $newcontent.$msgcon;
	}		
	
	public $format_img = array();	
	public $format_video = array();	
	public $format_count = 1;	 
	
	function face_format_message($content) {
		$content = preg_replace("/\{\:(.+?)\:\}/ies", "\$this->_setfaces('\\1')", $content);
		return $content;
	}	
	
	function _setimg($str='',$id=0) {
        $str = trim($str);
		$this->format_count++;			
        $this->format_img[] ='
				 <div  class="playerimages" id="pspplayer_'.$id.'_'.$this->format_count.'" onclick="pspplayer(\''.$id.'\',\''.$this->format_count.'\')" style=" display:none">
					<div class="playerimages_con">
						<div class="playerimages_box" id="pbox13737725258621536"><img src="'.$str.'" alt="" replace="false"></div>
					</div>
				</div>        

				<div class="previewimages" id="preview_'.$id.'_'.$this->format_count.'" onclick="pspplayer(\''.$id.'\',\''.$this->format_count.'\')" >								
					  <ul class="v">
							<li _href="'.$str.'"  class="v_play" id="loadFirstVideo"></li>
							<li class="v_thumb"><img src="'.$str.'" alt="" replace="false"></li>							
							<li class="v_border"></li>
					  </ul>
				</div>		
		';
		return '';
	}	
	
	function _setvideo($str='',$id=0) {
        $str = trim($str);
		$this->format_count++;		
        $this->format_video[] ='
				 <div  class="YK_player" id="pspplayer_'.$id.'_'.$this->format_count.'" onclick="pspplayer(\''.$id.'\',\''.$this->format_count.'\')" style=" display:none">
					<div class="player_con">
						<div class="player_box" id="pbox13737725258621536"><img src="'.$str.'" alt="" replace="false"></div>
					</div>
				</div>        

				<div class="preview" id="preview_'.$id.'_'.$this->format_count.'" onclick="pspplayer(\''.$id.'\',\''.$this->format_count.'\')" >								
					  <ul class="v">
							<li _href="'.$str.'" title="" _hz="tl_vthumb" class="v_play" _click="playv" data="" id="loadFirstVideo"></li>
							<li class="v_thumb"><img src="'.$str.'" alt="" replace="false"></li>							
							<li class="v_border"></li>
					  </ul>
				</div>		
		';
		return '';
	}		
	
	function _setfaces($str='') {
        $str = trim($str);
        foreach($this->faces as $k =>$v) {
		     if($v==$str){
				  return "<span class='smile_{$k}'></span>";
			 }
		}
		return $str;
	}		
	
	
}
?>